import 'dart:ui';

import 'package:wuxu_flutter_lianxi/redux/redux_login.dart';

import 'package:redux/redux.dart';

import '../model/user.dart';
import 'middleware/epic_store.dart';

///
/// 设置全局状态
///

class WXState {
  WXState(
      {this.userInfo,
      this.grey = false,
      this.locale,
      this.platformLocale});

  UserInfo? userInfo;
  //语言
  Locale? locale;
  //当前手机平台默认语言
  Locale? platformLocale;
  //通过color filter实现灰色模式
  bool grey;
}

///
/// redux包括下面几个：
///
/// 全局Store->middleware（可空）->reducer->新state->view->触发action->再传回全局Store
///

///
/// reducer
///
/// 本质是一个函数，返回值是与store设定的state类型或其子类。用于处理action，并根据旧状态生成一个新状态
///
/// 不论是哪个Action变化，最终都会走这个函数
WXState createReducer(WXState state, dynamic action) {
  print("action:${action.toString()}");

  return WXState(
      userInfo:  LoginReducer(state.userInfo, action),
      grey: state.grey,
      locale: state.locale,
      platformLocale: state.platformLocale);
}

///
/// 中间件
///
/// 中间件可以将Action转换为另一个Action
///
final List<Middleware<WXState>> wxMiddleware = [
  EpicMiddleware(epicLogin),
  // UserInfoMiddleware()
  LoginMiddleware()
];
